<script>
	var errorcodetableoption={
			toolbar: '#errorcodetoolbar',//工具按钮用哪个容器
			clickToSelect: true,// 单击行即可以选中
			singleSelect: true, //设置true禁止多选
			sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
            showPaginationSwitch: true,
			showExport: true,
			exportDataType: 'all',
			exportTypes: ['doc', 'excel'], //导出文件类型
			showToggle: true,  //是否显示视图切换按钮
			showRefresh: true,// 是否显示刷新按钮
			showColumns: true,//是否显示所有的列
			search: true, // 开启搜索功能
			pagination: true,// 开启分页功能
			sortName: "errorcode", // 设置默认排序为 name
			columns: [{
				field: "checked",
				checkbox: true
				}, {
				field: "schema",
				title: "模式",
				align: "center",
				valign: "middle"
				}, {
				field: "isused",
				title: "使用",
				align: "center",
				formatter : function (value, row, index) { switch(value) {case 1 :return "是"; default : return "否"}},
				valign: "middle"
				}, {
				field: "primekey",
				title: "主键",
				align: "center",
				valign: "middle"
				}, {
				field: "errorcode",
				title: "出错代码",
				visible: false,
				align: "center",
				valign: "middle"
				}, {
				field: "message",
				title: "信息",
				align: "center",
				valign: "middle"
			}],
			onlClickCell: function (field,value,row) {
					row.checked=true;
			},
			onCheck: function (row) {
				if (actions.includes("177")) {
					console.log(row)
					switch(row.isused) {
						case 0:$("#179").text("显示");break;
						case 1:$("#179").text("隐藏");break;
						default:$("#179").text("显示");break;
					}
					errorcodeEditTable(row);
				}
			}
		}

	$(function() {
		checkaction(new Array("176","177","179","180","181"));

		$("#errorcodeQueryTable").bootstrapTable(errorcodetableoption);
		$("#errorcodeQueryTable").bootstrapTable('showLoading');

		errorcodeQueryTable();
		$(".selectpicker").selectpicker("refresh");
		$("#errorcodemyModal").on("shown.bs.modal",function(e){ if ($("#txt_errorcode").attr("disabled")) { $("#txt_txt_message").focus() } else {$("#txt_errorcode").focus()}; });
	});
	
	function errorcodeAddTable() {//新增
		$("#txt_schema").val("");
		$("#txt_primekey").val("");
		$("#txt_errorcode").val("");
		$("#txt_errorcode").attr("disabled",false);
		$("#txt_message").val("");
        $("#errorcodemyModalLabel").html("新增");
        
	};
	
	function errorcodeEditTable(row) {
		if (row==null) {
			if ($("#errorcodeQueryTable").bootstrapTable('getSelections').length == 0) {
				alert("请先选择要修改的数据!");
				return;
			};
			row=$("#errorcodeQueryTable").bootstrapTable('getSelections')[0];
		}
		if (row.schema!=null) { $("#txt_schema").val(row.schema) } else { $("#txt_schema").val("")};
		if (row.primekey!=null) { $("#txt_primekey").val(row.primekey) } else { $("#txt_primekey").val("")};
		if (row.errorcode!=null) { $("#txt_errorcode").val(row.errorcode) } else { $("#txt_errorcode").val("")};
		$("#txt_errorcode").attr("disabled",true);
		if (row.message!=null) { $("#txt_message").val(row.message) } else { $("#txt_message").val("")};
        $("#errorcodemyModalLabel").html("修改");
        
	};
	
	function errorcodeCommitTable() {
		var errorcodecommitdata={
			schema:$("#txt_schema").val(),
			primekey:$("#txt_primekey").val(),
			errorcode:$("#txt_errorcode").val(),
			message:$("#txt_message").val(),
			token:token,
		};
		if ($("#errorcodemyModalLabel").html()=="新增") {
			ajaxarr([{
				url:"sysinfo/errorcode_add",
				title:"新增数据失败！",
				data:errorcodecommitdata,
				func:function(data) {
					alert("新增数据成功！id："+data.info.id);
					errorcodeQueryTable(data.info.id);
					errorcodeAddTable();
				}
			}]);
		} else {
			ajaxarr([{
				url:"sysinfo/errorcode_edit",
				title:"修改数据失败！",
				data:errorcodecommitdata,
				func:function(data) {
					alert("修改数据成功！");
					errorcodeQueryTable(errorcodecommitdata.errorcode);
					
				}
			}]);		
		};
	};
	
	function errorcodeDelTable() {
        var row = $("#errorcodeQueryTable").bootstrapTable('getSelections')[0];
        if(row == null) {
            alert("请先选择要删除的数据!");
            return;
        };       
		if(confirm( "您真的确定要删除吗？") == true) {
			ajaxarr([{
				url: "sysinfo/errorcode_del" ,
				title: "删除数据失败！",
				data:{token:token,errorcode : row.errorcode },
				func: function(data) {
					alert("删除成功！");
					errorcodeQueryTable();
				}
			}]);
		}
	};
	
	function errorcodeDelTableUndelTable() {
        var row = $("#errorcodeQueryTable").bootstrapTable('getSelections')[0];
        if(row == null) {
            alert("请先选择要恢复的数据!");
            return;
        };       
		if(confirm( "您真的确定要恢复吗？") == true) {
			ajaxarr([{
				url: "sysinfo/errorcode_undel" ,
				title: "恢复数据失败！",
				data:{token:token,errorcode : row.errorcode },
				func: function(data) {
					alert("恢复成功！");
					errorcodeQueryTable();
				}
			}]);
		}
	}


	function errorcodeQueryTable(id) {
		$("#errorcodeQueryTable").bootstrapTable('showLoading');
		ajaxarr([{
				url:"sysinfo/errorcode_query",
				title:"获取出错代码信息失败，请刷新！",
				data:{token:token},
				func: function (data) {
					if (data.info.total==0) { $("#errorcodeQueryTable").bootstrapTable("destroy").bootstrapTable(errorcodetableoption); } 
					else {	
						$("#errorcodeQueryTable").bootstrapTable('load', data.info.rows); 
						if (id) {
							for (var i=data.info.total;i>0;i--) {
								if (data.info.rows[i-1].errorcode==id) {
									$("#errorcodeQueryTable").bootstrapTable('selectPage', Math.ceil(i/$("#errorcodeQueryTable").bootstrapTable('getOptions').pageSize));
									$("#errorcodeQueryTable").bootstrapTable('checkBy',{field:'errorcode',values:[data.info.rows[i-1].errorcode]})
									break;
								};							
							}
						} else {
							$("#errorcodeQueryTable").bootstrapTable('checkBy',{field:'errorcode',values:[data.info.rows[0].errorcode]})
							errorcodeEditTable(data.info.rows[0]);
						}
					};
					$("#errorcodeQueryTable").bootstrapTable('hideLoading');
				}
		}]);		
	};
</script>
<table id="errorcodeQueryTable" class='table-striped'></table>
<!-- <div id="errorcodetoolbar" class="btn-group">
	<button id="176" type="button" style="display:none;" class="btn btn-default" onclick="errorcodeAddTable()"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增</button>
	<button id="177" type="button" style="display:none;" class="btn btn-default" onclick="errorcodeEditTable()"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>修改</button>
	<button id="179" type="button" style="display:none;" class="btn btn-default" onclick="errorcodeDelTable()"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除</button>
	<button id="181" type="button" style="display:none;" class="btn btn-default" onclick="errorcodeUndelTable()"><span class="glyphicon glyphico-ok" aria-hidden="true"></span>恢复</button>
	<button id="180" type="button" style="display:none;" class="btn btn-default" onclick="errorcodeQueryTable()"><span class="glyphicon glyphico-query" aria-hidden="true"></span>查询</button>
</div>
<div class="row" id="errorcodemyModal" tabindex="-1" >
	<div class="col-12" >
		<div class="modal-content" >
			<div class="modal-header">
				<h4 class="modal-title" id="errorcodemyModalLabel">新增</h4>
				
			</div>
			<div class="modal-body form-inline">
				<label for="txt_schema" class="col-lg-3 text-center">模式</label><input id="txt_schema" class="form-control col-lg-3" onkeypress="{ if (event.keyCode==13) {txt_primekey.focus()}}" type="text" placeholder="模式"/>
				<label for="txt_primekey" class="col-lg-3 text-center">主键</label><input id="txt_primekey" class="form-control col-lg-3" onkeypress="{ if (event.keyCode==13) {txt_errorcode.focus()}}" type="text" placeholder="主键"/>
				<label for="txt_errorcode" class="col-lg-3 text-center">出错代码</label><input id="txt_errorcode" class="form-control col-lg-3" disabled="disabled" onkeypress="{ if (event.keyCode==13) {txt_message.focus()}}" type="text" placeholder="出错代码"/>
				<label for="txt_message" class="col-lg-3 text-center">信息</label><input id="txt_message" class="form-control col-lg-3" onkeypress="{ if (event.keyCode==13) {SaveModal.focus()}}" type="text" placeholder="信息"/>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal" onclick="errorcodeAddTable()"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span>清空</button>
				<button type="button" class="btn btn-primary" id="errorcodeSaveModal" onclick="errorcodeCommitTable()"><span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>保存</button>
			</div>
		</div>
	</div>
</div> -->
